class Alg<T extends Comparable<T>> {
    //定义一个泛型类，找到数组的最大值
    public T findMax(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (array[i].compareTo(max) > 0) {
                max = array[i];
            }
        }
        return max;
    }
}

class Alg1 {
    //泛型方法
    public <T extends Comparable<T>> T findMax(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (array[i].compareTo(max) > 0) {
                max = array[i];
            }
        }
        return max;
    }
}

public class Demo1_4 {
    //泛型的上界
    public static void main(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {1, 2, 3, 4, 5, 6, 7, 8};
        Integer max = alg.findMax(array);
        System.out.println(max);
        Alg1 alg1 = new Alg1();
        Integer[] array1 = {1, 2, 3, 4, 5, 6};
        Integer ret = alg1.findMax(array1);
        System.out.println(ret);
    }
}
